<?php #20070508 http://www.framework.altervista.org/FrameWork/applications/_admin/system/backup/application.inc
define('APPBACKUP','1.00');
/************************************************************************/
/* FrameWork  test preview                                              */
/* ==================================================================== */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/

loadlib("libArchivedir");

if (!file_exists("datas/backup"))
    mkdir("datas/backup");
//I BACKUP NON POSSONO ESSERE CONSERVATI SUL SITO:E' TROPPO PERICOLOSO!!!
$fd=opendir("datas/backup/");
while (false !== ($nf= readdir($fd))){
    if ($nf[0]!='.' )
	unlink("datas/backup/$nf");
}
//-----------------------------------------------------------------------------------------------------------------------

// backup site
function backup(){
    admin_writelog("admin backup:execute backup");

    $nome_backup="datas/backup/backup-".date("Y.m.d:H.i").".zip";
    $backup = new zip_file($nome_backup);
    $backup->set_options(array('inmemory'=>"0",'overwrite'=>1,'storepaths','prepend','level','type'=>"zip"));

    if ($_POST['_datas_app']){
	$dir = new DeepDir();
	$dir->setDir("datas/applications");
	$dir->load();
	foreach($dir->files as $nf){
	    $backup->add_files($nf);
	}
	$dir = new DeepDir();
	$dir->setDir("datas/blocks");
	$dir->load();
	foreach($dir->files as $nf){
	    $backup->add_files($nf);
	}
    echo "datas applications...done <br />";
    }

    if ($_POST['_datas_sb']){
	$dir = new DeepDir();
	$dir->setDir("datas/sb");
	$dir->load();
	foreach($dir->files as $nf){
	    $backup->add_files($nf);
	}
    echo "datas security box...done <br />";
    }

    if ($_POST['_applications']){
	$dir = new DeepDir();
	$dir->setDir("applications");
	$dir->load();
	foreach($dir->files as $nf){
	    $backup->add_files($nf);
 	}
    echo "applications...done <br />";
    }

    if ($_POST['_blocks']){
	$dir = new DeepDir();
	$dir->setDir("blocks");
	$dir->load();
	foreach($dir->files as $nf){
	    $backup->add_files($nf);
	}
    echo "blocks...done <br />";
    }

    if ($_POST['_extras']){
	$dir = new DeepDir();
	$dir->setDir("extras");
	$dir->load();
	foreach($dir->files as $nf){
	    $backup->add_files($nf);
	}
    echo "extras...done <br />";
    }

    if ($_POST['_js']){
	$dir = new DeepDir();
	$dir->setDir("js");
	$dir->load();
	foreach($dir->files as $nf){
	    $backup->add_files($nf);
	}
    echo "js...done <br />";
    }



    if ($_POST['_libs']){
	$dir = new DeepDir();
	$dir->setDir("libs");
	$dir->load();
	foreach($dir->files as $nf){
	    $backup->add_files($nf);
	}
    echo "libs...done <br />";
    }

    if ($_POST['_themes']){
	$dir = new DeepDir();
	$dir->setDir("themes");
	$dir->load();
	foreach($dir->files as $nf){
	    $backup->add_files($nf);
	}
    echo "themes...done <br />";
    }

    if ($_POST['_doc']){
	$dir = new DeepDir();
	$dir->setDir("doc");
	$dir->load();
	foreach($dir->files as $nf){
	    $backup->add_files($nf);
	}
    echo "documentation...done <br />";
    }


    if ($_POST['_core']){
	$backup->add_files("index.php");
	$backup->add_files("libMain.js");
	$backup->add_files("config.inc");

    echo "core...done <br />";
    }

    $backup->create_archive();
    echo "<hr />";
    echo "scarica <a href='$nome_backup'>$nome_backup</a>\n";
    echo "<p align='right'> [<a href='index.php?appname=$appname'>continua</a>]</p>\n";
}
//-----------------------------------------------------------------------------------------------------------------------
?>
<?php if (admin_isadmin()){?>
        <h3>Backup</h3><hr />
	<p>
<?php

$op=$_GET['op'];
switch ($op){
    case "backup":
	backup();
	break;
    default:
?>
<form action="index.php?appname=<?=$appname?>&op=backup" method="post">
<b>DATAS</b><br/>
<input type='checkbox' name='_datas_app' /> <b>Applications</b> <br />
<input type='checkbox' name='_datas_sb' /> <b>Security box</b> <br />
<br />
<b>CODICE</b><br/>
<input type='checkbox' name='_applications' /> <b>Applications</b> <br />
<input type='checkbox' name='_blocks' /> <b>Blocks</b> <br />
<input type='checkbox' name='_extras' /> <b>Extras</b> <br />
<input type='checkbox' name='_js' /> <b>Js</b> <br />
<input type='checkbox' name='_libs' /> <b>Libs</b> <br />
<input type='checkbox' name='_themes' /> <b>Themes</b> <br />
<input type='checkbox' name='_doc' /> <b>Documentation</b> <br />
<input type='checkbox' name='_core' /> <b>Core</b> <br />
<hr />
<input type='submit' value=' execute backup ' />
</form>
<?php
    break;
    }
?>
</p>
<?php  } ?>
